package com.fangda.network.websocket.client;

import com.fangda.network.NetworkConfig;
import com.fangda.network.NetworkProvider;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;

public class WebsocketClientProvider implements NetworkProvider<WebsocketClientNetwork> {

    @Override
    public WebsocketClientNetwork createNetwork(Vertx vertx, String id, NetworkConfig networkConfig) {
        HttpClientOptions config = (HttpClientOptions)networkConfig.getConfig().getOrDefault("options", new HttpClientOptions());
        WebsocketClientNetwork network = new WebsocketClientNetwork(id, networkConfig);
        HttpClient httpClient = vertx.createHttpClient(config);
        network.setHttpClient(httpClient);
        return network;
    }
}
